//
//  Refresh.swift
//  Spookiness
//
//  Created by 腾億 on 2017/12/8.
//  Copyright © 2017年 tml. All rights reserved.
//

import Foundation
import MJRefresh

extension UIScrollView {
    var refrshHead: MJRefreshHeader {
        get {
            return mj_header
        }
        set {
            mj_header = newValue
        }
    }
    
    var refreshFoot:MJRefreshFooter {
        get {
            return mj_footer
        }
        set {
            mj_footer = newValue
        }
    }
    
}

class RefreshGifHeader: MJRefreshGifHeader {
    override func prepare() {
        super.prepare()
        // 设置普通状态图片
        setImages([UIImage(named: "refresh_normal")!], for: .idle)
        //设置下拉时候图片
        setImages([UIImage(named: "refresh_will_refresh")!], for: .pulling)
        //设置正在刷新状态的动画图片
        setImages([UIImage(named: "refresh_loading_1")!,
                   UIImage(named: "refresh_loading_2")!,
                   UIImage(named: "refresh_loading_3")!], for: .refreshing)
        //将时间提示label隐藏
        lastUpdatedTimeLabel.isHidden = true
        stateLabel.isHidden = true
    }
}

class RefreshHeader: MJRefreshHeader {
    
}

class RefreshBackNormalFooter: MJRefreshBackNormalFooter {
    
}

class RefreshAutoFooter: MJRefreshAutoFooter {
    
}

class RefreshBackGifFooter: MJRefreshBackGifFooter {
    override func prepare() {
        backgroundColor = kRGBA(r: 242, g: 242, b: 242, a: 1)
        setImages([UIImage(named: "refresh_discover")!], for: .idle)
        stateLabel.isHidden = true
        refreshingBlock = {
            self.endRefreshing()
        }
    }
}

class RefreshBackFooter: MJRefreshBackFooter {
    lazy var tipLabel: UILabel = {
       let label = UILabel()
        label.textAlignment = .center
        label.textColor = UIColor.lightGray
        label.font = UIFont.systemFont(ofSize: 14)
        label.numberOfLines = 0
        return label
    }()
    
    lazy var imageView: UIImageView = {
       let imgV = UIImageView()
        imgV.image = #imageLiteral(resourceName: "refresh_kiss")
        return imgV
    }()
    
    override func prepare() {
        super.prepare()
        backgroundColor = kRGBA(r: 242, g: 242, b: 242, a: 1)
        mj_h = 240
        addSubview(self.tipLabel)
        addSubview(self.imageView)
    }
    
    override func placeSubviews() {
        tipLabel.frame = CGRect(x: 0, y: 40, width: bounds.width, height: 60)
        imageView.frame = CGRect(x: (bounds.width - 80 ) / 2, y: 110, width: 80, height: 80)
    }
    
    convenience init(with tip: String) {
        self.init()
        refreshingBlock = { self.endRefreshing() }
        tipLabel.text = tip
    }
    
}





